package com.tiny.work.btrace.Counter;

import com.sun.btrace.annotations.*;

import static com.sun.btrace.BTraceUtils.*;

@BTrace
public class TraceExecuteTime {
    @TLS private static long startTime = 0;

    @OnMethod(
            clazz="com.sample.test.Counter",
            method="add"
    )
    public static void start(){
        startTime = timeNanos();
    }

    @OnMethod(
            clazz="com.sample.test.Counter",
            method="add",
            location=@Location(Kind.RETURN)
    )
    public static void endExecute(@Duration long duration) {
        long time = timeNanos() - startTime;
        println(strcat("execute time(nanos):" , str(time/(60 * 60 * 24 * 1000))));
        println(strcat("duration(nanos):", str(duration/(60 * 60 * 24 * 1000))));
    }
}
